﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using LotteryVote.Logic.Exceptions;

namespace LotteryVote.Logic.Bet
{
    internal class PL3NumQuantityCounter : NumQuantityCounter
    {
        public override int CountNumQuantity(string num, Entity.PlayWay playWay)
        {
            if (!IsPL3(num))
                throw new ArgumentException(string.Format("num:{0} not a pl3 number", num));
            if (this.CompanySupportNumLen == null || this.CompanySupportNumLen.Count == 0)
                throw new ApplicationException("公司支持号码长度不能为空!");
            var nums = num.Split('#');
            foreach (var n in nums)
            {
                if (nums.Count(it => it == n) > 1)
                    throw new InvalidDataException("包组过关3应该使用3个不相同的号码!");
            }
            return CompanySupportNumLen.Sum(it => it.Count) * 3;
        }

        private bool IsPL3(string num)
        {
            Regex rule = new Regex(@"^\d{2}#\d{2}#\d{2}$");
            return rule.IsMatch(num);
        }

        public override string GetRealyBetNum(string num)
        {
            return num;
        }
    }
}
